package executors.completable.future;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ExceptionallyTest001 {
  public static void main(String[] args) throws ExecutionException, InterruptedException {
    ExecutorService executorService = Executors.newSingleThreadExecutor();
    
    CompletableFuture<String> result = CompletableFuture.supplyAsync(() -> {
      System.out.println("基础线程A");
      return "A";
    }, executorService).thenApplyAsync((res) -> {
      System.out.println("基础线程B , 接受到返回值是: " + res);
      return "B" + res;
    }, executorService).thenApplyAsync((res) -> {
      int count = 1 / 0;
      System.out.println("基础线程C , 接受到返回值是: " + res);
      return "C" + res;
    }, executorService).exceptionally((res) -> {
      System.out.println("基础线程ERROR , 接受到返回值是: " + res);
      return "ERROR" + res;
    });
    
    System.out.println(result.get());
  }
}
